import Vuex from "vuex";
import Vue from "vue";
Vue.use(Vuex);
export default new Vuex.Store({
  modules: { },
  state: {
    wxNickname: null,
    userMobile: null,
    userId: null,
    avatarUrl: null,
    companyCode: null,
    lastOrderUpdateTime: null,
    token: null,
    avatarUrl: null,
    devAgent: null,
    // "Bearer eyJhbGciOiJIUzI1NiIsInppcCI6IkRFRiJ9.eNqqVspMLFGyMjQzNDE1MzQ1NdVRSq0ogAiYGZiYgwSS83MLEvMqnfNTUpWslCK9Ij2UgKpyC3LyK1NTPVOAihFcv8RckKJn8ydAkFItAAAA__8.WeWpL-C-TmD2kvDq06U5V5106Z0H3P_lDXR1pj-AH-Q"
    orderSelectYear: null, // 订单列表选中历史订单的年份
  },
  mutations: {
    setCityIntroduce(state, value) {
      state.cityIntroduce = value;
    },
    refreshOrder(state) {
      state.lastOrderUpdateTime = new Date().getTime();
    },
    setCompanyCode(state, value) {
      state.companyCode = value;
    },
    setAvatarUrl(state, value) {
      state.avatarUrl = value;
    },
    setUserInfo(state, info) {
      const {
        token,
        mobile: userMobile,
        userId,
        wxNickname,
        avatarUrl,
        devAgent,
      } = info;
      Object.assign(state, {
        token: `Bearer ${token}`,
        userMobile,
        userId,
        wxNickname,
        avatarUrl,
        devAgent,
      });
    },
    clearUserInfo(state) {
      console.log("clearUserInfo:", state);
      state.token = null;
      state.userMobile = null;
      state.userId = null;
      state.wxNickname = null;
      state.avatarUrl = null;
      // state = {
      //   token: null,
      //   userMobile: null,
      //   userId: null ,
      //   wxNickname: null,
      //   avatarUrl: null
      // };
      console.log("clearUserInfo:", state);
    },
	setOrderSelectYear(state, value) {
		console.log(value);
      	state.orderSelectYear = value;
    },
  },
});
